import React from 'react';
import { renderNumber } from '@/utils/common';
import CommonPage from '@/components/page/CommonPage';
import { useModel } from 'umi';
const daoName = 'ShLrjs';
const importName = 'ShLrjs';
const columns: API.Column[] = [
  {
    title: '考核年份',
    width: 110,
    sorter: true,
    dataIndex: 'KHNF',
    key: 'KHNF',
    dispaly: true,
    filter: true,
    export: true,
  },
  {
    title: '员工号',
    width: 80,
    sorter: true,
    dataIndex: 'EMNO',
    key: 'EMNO',
    dispaly: true,
    filter: true,
    export: true,
  },
  {
    title: '员工名',
    width: 80,
    sorter: true,
    dataIndex: 'EMNM',
    key: 'EMNM',
    dispaly: true,
    filter: true,
    export: true,
  },
  {
    title: '部门',
    width: 80,
    sorter: true,
    key: 'UTNM',
    dataIndex: 'UTNM',
    dataType: 'string',
    dispaly: true,
    filter: true,
  },
  {
    title: '公司利润基数(万元)',
    width: 150,
    className: 'column-money',
    sorter: true,
    dataIndex: 'GSLRJS',
    render: (data) => renderNumber('.2f', data),
    key: 'GSLRJS',
    dispaly: true,
    align: 'right',
    filter: true,
    export: true,
  },
  {
    title: '零售利润基数(万元)',
    width: 150,
    className: 'column-money',
    sorter: true,
    dataIndex: 'LSLRJS',
    render: (data) => renderNumber('.2f', data),
    key: 'LSLRJS',
    dispaly: true,
    align: 'right',
    filter: true,
    export: true,
  },
  {
    title: '金融市场利润基数(万元)',
    width: 170,
    className: 'column-money',
    sorter: true,
    dataIndex: 'JRSCLRJS',
    render: (data) => renderNumber('.2f', data),
    key: 'JRSCLRJS',
    dispaly: true,
    align: 'right',
    filter: true,
    export: true,
  },
  {
    title: '总利润基数(万元)',
    width: 150,
    className: 'column-money',
    sorter: true,
    dataIndex: 'ZLRJS',
    render: (data) => renderNumber('.2f', data),
    key: 'ZLRJS',
    dispaly: true,
    align: 'right',
    filter: true,
    export: true,
  },
];

const controlsImport: API.Control[] = [
  {
    name: 'KHNF',
    type: 'year',
    label: '年份',
    dataType: 'number',
    grid: 12 / 24,
    rules: [{ required: true, message: '年份不能为空' }],
  },
  { name: 'EMNO', type: 'text', label: '员工号', grid: 12 / 24 },
  { name: 'EMNM', type: 'text', label: '员工名', grid: 12 / 24 },
  { name: 'UTNM', type: 'text', label: '部门', grid: 12 / 24 },
  {
    name: 'ZLRJS',
    label: '总利润基数(万元)',
    rules: [{ required: false, message: '不能为空' }],
    type: 'number',
    dataType: 'number',
    grid: 12 / 24,
  },
  {
    name: 'GSLRJS',
    label: '公司利润基数(万元)',
    rules: [{ required: false, message: '不能为空' }],
    type: 'number',
    dataType: 'number',
    grid: 12 / 24,
  },
  {
    name: 'LSLRJS',
    label: '零售利润基数(万元)',
    rules: [{ required: false, message: '不能为空' }],
    type: 'number',
    dataType: 'number',
    grid: 12 / 24,
  },
  {
    name: 'JRSCLRJS',
    label: '金融市场利润基数(万元)',
    rules: [{ required: false, message: '不能为空' }],
    type: 'number',
    dataType: 'number',
    grid: 12 / 24,
  },
];

const controls: API.Control[] = [
  {
    name: 'KHNF',
    type: 'year',
    label: '年份',
    dataType: 'number',
    grid: 12 / 24,
    rules: [{ required: true, message: '年份不能为空' }],
  },
  { name: 'EMNO', type: 'text', label: '员工号', grid: 12 / 24 },
  { name: 'EMNM', type: 'text', label: '员工名', grid: 12 / 24 },
  {
    name: 'UTNM',
    label: '所属部门',
    type: 'select',
    grid: 12 / 24,
    fetch: {
      tableName: 'Organization',
      optionTpl: 'Name',
      valueTpl: 'Name',
      isDao: true,
    },
    dataType: 'string',
    placeholder: '请选择所属部门...',
    rules: [{ required: true, message: '所属部门不能为空' }],
  },

  {
    name: 'ZLRJS',
    label: '总利润基数(万元)',
    rules: [{ required: false, message: '不能为空' }],
    type: 'number',
    dataType: 'number',
    grid: 12 / 24,
  },
  {
    name: 'GSLRJS',
    label: '公司利润基数(万元)',
    rules: [{ required: false, message: '不能为空' }],
    type: 'number',
    dataType: 'number',
    grid: 12 / 24,
  },
  {
    name: 'LSLRJS',
    label: '零售利润基数(万元)',
    rules: [{ required: false, message: '不能为空' }],
    type: 'number',
    dataType: 'number',
    grid: 12 / 24,
  },
  {
    name: 'JRSCLRJS',
    label: '金融市场利润基数(万元)',
    rules: [{ required: false, message: '不能为空' }],
    type: 'number',
    dataType: 'number',
    grid: 12 / 24,
  },
];

const ShLrjs: React.FC = () => {
  const { edwDate } = useModel('@@initialState', (ret) => {
    return {
      edwDate: ret.initialState?.sys?.edwDate,
    };
  });
  const options: API.OptionItem[] = [];
  const curdate = new Date(edwDate!);
  const year = curdate.getFullYear();
  for (let i = year; i >= year - 10; i--) {
    options.push({ label: `${i}年`, value: i });
  }
  return (
    <CommonPage
      daoName={daoName}
      columns={columns}
      controls={controls}
      title="利润基数"
      importName={importName}
      importControls={controlsImport}
      importParamNames={['KHNF']}
      importMode="DeleteAfterInsert"
      importTemplateName="利润基数导入模板"
      initSorter={{ FieldName: 'KHNF', Direction: 'DESC' }}
      keyColName="JLID"
    />
  );
};
export default ShLrjs;
